home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / BUS / TMCM Software and Labs.sit / Software for TMCM 7_95 / Files for Lab 11 / Koch Curves next >
Text File  |  1993-10-31  |  2KB  |  90 lines

  1. SUB Koch(dist,complexity)
  2.  
  3.  { Makes the Turtle move forward a distance of
  4.    dist, following a Koch curve of the given
  5.    complexity. }
  6.  
  7.    IF complexity <= 1 THEN
  8.       forward(dist)
  9.    ELSE
  10.       koch(dist/3, complexity - 1)
  11.       turn(60)
  12.       koch(dist/3, complexity - 1)
  13.       turn(-120)
  14.       koch(dist/3, complexity - 1)
  15.       turn(60)
  16.       koch(dist/3, complexity - 1)
  17.    END IF
  18.  
  19. END SUB
  20.  
  21.  
  22.  
  23. SUB TestKoch
  24.  
  25.  { This subroutine can be called to draw sample Koch curves;
  26.    the user is asked to specify the complexity and a
  27.    Koch curve of that complexity is drawn stretch across most 
  28.    of the screen. }
  29.  
  30.    DECLARE complexity
  31.  
  32.    penUp
  33.    MoveTo(-9,0)
  34.    penDown
  35.    face(0)
  36.    clear
  37.  
  38.    AskUser("What level of complexity do you want (0 to 7)?", complexity)
  39.  
  40.    complexity := trunc(complexity)  { Make sure value is OK }
  41.    IF complexity < 0 THEN
  42.       complexity := 0
  43.       TellUser("Using complexity = 0.")
  44.    END IF
  45.    IF complexity > 7 THEN
  46.       complexity := 7
  47.       TellUser("Using complexity = 7.")
  48.    END IF
  49.  
  50.    Koch(18,complexity)
  51.  
  52. END SUB
  53.  
  54.  
  55.  
  56. SUB Snowflake
  57.  
  58.  { This is similar to TestKoch, except that it draws
  59.    a "snowflake" curve consisting of three Koch curves
  60.    laid out in a triangle. }
  61.  
  62.    DECLARE complexity
  63.  
  64.    penUp
  65.    MoveTo(-6,4)
  66.    penDown
  67.    face(0)
  68.    clear
  69.  
  70.    AskUser("What level of complexity do you want (0 to 7)?", complexity)
  71.  
  72.    complexity := trunc(complexity)  { Make sure value is OK }
  73.    IF complexity < 0 THEN
  74.       complexity := 0
  75.       TellUser("Using complexity = 0.")
  76.    END IF
  77.    IF complexity > 7 THEN
  78.       complexity := 7
  79.       TellUser("Using complexity = 7.")
  80.    END IF
  81.  
  82.    Koch(12,complexity)
  83.    turn(-120)
  84.    Koch(12,complexity)
  85.    turn(-120)
  86.    Koch(12,complexity)
  87.  
  88. END SUB
  89.  
  90.